package com.agranee.timesheet.dao;

import java.util.List;

import org.hibernate.SessionFactory;

import com.agranee.timesheet.daoable.Countryable;
import com.agranee.timesheet.model. Country;


public class CountryDao implements Countryable {

	private SessionFactory sessionFactory;

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@Override
	public void addCountry(Country country) {
		getSessionFactory().getCurrentSession().save(country);

	}

	@Override
	public Country getCountryById(int countryId) {
		List<Country> list = getSessionFactory().getCurrentSession()
				.createQuery("from country where id=:countryId")
				.setParameter("countryId", countryId).list();
		return list.get(0);
	}

	@Override
	public List<Country> getAllCountryId() {
		List<Country> list = getSessionFactory().getCurrentSession()
				.createQuery("select id from country").list();
		return list;
	}
	
	public List<Country> getAllCountry(){
		List<Country> list = getSessionFactory().getCurrentSession()
				.createQuery("from country").list();
		return list;
		
	}
	
}
